/*
 * Copyright 2007 National Bioinformatics Network
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package dgbgui.modeldocument.definition;


import dgbgui.modeldocument.Query;
import dgbgui.modeldocument.primitives.ConceptType;
import dgbgui.modeldocument.primitives.ConceptronType;
import dgbgui.modeldocument.primitives.RelationType;


public class PathDefinition extends Definition implements  Cloneable {

    
    public PathDefinition(Query from, Query to, ConceptronType throughType) {
        assert ( ( throughType instanceof ConceptType ) ||
                 ( throughType instanceof RelationType ) );
        m_from = from;
        m_to = to;
        m_throughTypeString = getThroughTypeQLString(throughType);
    }

    public String getTypeName() {
        return "Path";
    }

    public String getdgbQLString() {
        return getThroughTypeQLString() + "("
            + m_from.getDefinition().getdgbQLString() + ","
            + m_to.getDefinition().getdgbQLString() + ")";
        
    }
    

    public String getThroughTypeQLString() {
        return m_throughTypeString;
    }
    
    private String getThroughTypeQLString(Object type) {
        if ( type instanceof ConceptType ) {
            return "ct:" + ((ConceptType)type).m_name;
        } else if ( type instanceof RelationType ) {
            return "rt:" + ((RelationType)type).m_name;
        } else {
            assert false;
            return "";
        }
    }
    
    public Query getFrom() {
        return m_from;
    }
    
    public Query getTo() {
        return m_to;
    }
    
    // ------------------- Serialization -------------
    
    /**
     * First serilization version
     */
    private static final long serialVersionUID = 1L;

    // ---------- Fields ----------
    
    
    // The from, to and type of the path
    Query m_from,m_to;
    String m_throughTypeString;

}
